<style>
    #tree_content{padding-top: 10px;}
</style>
<div class="layui-col-md2" id="engindao">
    <div class="engindao_bac">
        <div class="engindao_div">
            <div class="engindao_title">过期时间导航</div>
            <div class="engindao_nav">
                <a id="engindao_left"><i class="layui-icon layui-icon-left"></i></a>
            </div>
        </div>
<!--        <div>-->
<!--            <input type="text" id="engindao_name" placeholder="证书分类名称" class="layui-input" autocomplete="off">-->
<!--            <button id="engindao_sea" class="laytp-btn" type="button"><i class="layui-icon layui-icon-search"></i></button>-->
<!--        </div>-->
<!--        <div>-->
<!--            <button id="engindao_all" type="button" class="layui-btn layui-btn-sm typeall engin_dao_dian">-->
<!--                <i class="layui-icon layui-icon-home"></i>&nbsp;&nbsp;&nbsp;全部-->
<!--            </button>-->
<!--        </div>-->
        <div id="tree_content"></div>
    </div>
</div>
<div class="layui-col-md2 layui-hide" id="engindaomin">
    <div class="engindao_bg">
        <div class="col" id="engindao_right"><a><i class="layui-icon layui-icon-right"></i></a></div>
        <div class="engindao_title">过期时间导航</div>
    </div>
</div>
<script>
    var daoPage = 1, daoPagesize = 20, daoFinish = false;
    layui.use(["laytp",'tree','laypage','table','dropdown','form','soulTable'], function () {
        var tree = layui.tree,laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown,
            form = layui.form, soulTable = layui.soulTable;

        getEnginDaoData();
        $("#engindao #engindao_left").click(function () {
            var cliHeight = document.getElementById('engindao').clientHeight;

            $("#engindao").addClass('layui-hide');
            $("#table-card #table_list").addClass('engindaomin_guan');

            document.getElementById('engindaomin').style.height = cliHeight+"px";
            $("#engindaomin").removeClass('layui-hide');
        });
        $("#engindaomin #engindao_right").click(function () {
            $("#engindao").removeClass('layui-hide');
            $("#table-card #table_list").removeClass('engindaomin_guan');
            $("#engindaomin").addClass('layui-hide');
        });

        $('#engindao #engindao_all').click(function () {
            $(this).addClass('engin_dao_dian');
            $("#engindao_content .cons .lis").removeClass('engin_dao_dian');
            $('.layui-tree-entry').each(function () {
                $(this).find('.layui-tree-txt').removeClass('layui-tree-other');
            });
            $("#enginid").val(0)
            searchTableFunc(form, table);
        });

        $('#engindao #engindao_sea').click(function () {
            daoPage = 1;
            $("#engindao_content .cons").html('');
            enginDataLoading();
            getEnginDaoData()
        });


        $('.typeall').click(function () {
            $('.layui-tree-entry').each(function () {
                $(this).find('.layui-tree-txt').removeClass('layui-tree-other');
            });
            $("#daytype").val('');
            searchTableFunc(form, table);
        });


        function getEnginDaoData() {
            if(daoFinish){
                return false;
            }

            var data = [{id:1,title:'30天内即将过期',checked:true},{id:2,title:'60天内即将过期'},{id:3,title:'90天内即将过期'},{id:4,title:'已过期'}];
            treeObj = tree.render({
                elem: '#tree_content'
                ,id: 'tree_content'
                ,data: data
                ,onlyIconControl: true
                ,click: function(obj){
                    $("#daytype").val(obj.data.id);
                    searchTableFunc(form, table);

                    $('.layui-tree-entry').each(function () {
                        $(this).find('.layui-tree-txt').removeClass('layui-tree-other');
                    });
                    $(obj.elem).find('.layui-tree-entry').eq(0).find('.layui-tree-txt').addClass('layui-tree-other');
                    $('#engindao_all').removeClass('engin_dao_dian');
                }
            });

            $('.layui-tree-entry').eq(0).find('.layui-tree-txt').addClass('layui-tree-other');



            $("#engindao_content .cons .lis").click(function () {
                $("#engindao  #engindao_all").removeClass('engin_dao_dian');
                $("#engindao_content .cons .lis").removeClass('engin_dao_dian');
                $(this).addClass('engin_dao_dian');


                var thisEnginid = parseInt($(this).attr('key')) || 0;
                $("#enginid").val(thisEnginid)
                searchTableFunc(form, table);
            });


            var height = $('.laytp-container').height() - 270 + 'px';
            $('#tree_content').css('cssText','max-height:'+height);
        }



        $('#engindao #engindao_content').scroll(function (e) {
            if (isScrollBottom(this)) {
                if(!daoFinish){
                    enginDataLoading();
                    daoPage += 1;
                    getEnginDaoData();
                }
            }
        });
    })





    function isScrollBottom(obj) {
        if (obj.scrollTop + obj.clientHeight === obj.scrollHeight) {
            return true;
        } else {
            return false;
        }
    }


    function enginDataLoading() {
        daoFinish = false;
        $("#engindao #engindao_content #loading_text").html('数据加载中...');
    }
    function enginDataFinish() {
        daoFinish = true;
        $("#engindao #engindao_content #loading_text").html('数据已全部加载');
    }


</script>
